import AuthenticationSelect from '@/components/AuthenticationSelect';
import BelongSelect from '@/components/BelongSelect';
import { AntdModalProps } from '@/hooks/useAntdModal';
import { saveCertificate, savePipeline } from '@/service/globalSetting';
import { Checkbox, Form, Input, Modal, Radio, Select } from 'antd';
import React from 'react';
const SavePipeline = ({ form,closeModal,refresh, modalProps }: AntdModalProps) => {
  const onOk = async () => {
    let data = await form.validateFields()
    data.default = data.default ? 0 : 1
     await savePipeline(data)
     closeModal();
     refresh()
  }
  return (<Modal width={800}  title="流水线保存" {...modalProps} onOk={onOk}>
    
    <Form form={form} labelCol={{ span:7 }}
      initialValues={{
        belong: '1',
        mode:'api'
      }}
    >
       <Form.Item required name='belong' label='项目归属'>
        <BelongSelect/> 
      </Form.Item>
      <Form.Item label="流水线名称"  rules={[{
        required: true,
        message: '流水线名称'
      }]} name='title'>
        <Input />
      </Form.Item>
  
      <Form.Item hidden name='id'>
        <Input />
      </Form.Item>
      <Form.Item noStyle shouldUpdate={(a,b)=>a.belong!==b.belong}>
   {({getFieldValue})=>{
    if(getFieldValue('belong')==='codeup'){
      return <>
         <Form.Item label='DEV触发地址' name='devWebhook'>
          <Input/>
         </Form.Item>
         <Form.Item label='TEST触发地址' name='testWebhook'>
          <Input/>
         </Form.Item>
      </>
    }
    return <>
    <Form.Item label="jenkins视图名称"  rules={[{
        required: true,
        message: 'jenkins视图描述'
      }]} name='view'>
        <Input />
      </Form.Item>
      <Form.Item label="视图类型" name='viewType' rules={[{
        required: true,
        message: '视图类型'
      }]}>
        <Select placeholder="请选择" options={[{
          value: 'Npm',
          label: 'Npm'
        }, {
          value: 'WEB',
          label: 'WEB'
        }, {
          value: '微信小程序',
          label: 'GitLab'
        }]} />
      </Form.Item>

    </>
   }}
      </Form.Item>

      
      <Form.Item label="凭证" name='certificateId' >
        <AuthenticationSelect placeholder='使用凭证' />
      </Form.Item>
      



      <Form.Item label="是否默认" name='default' >
        <Checkbox />
      </Form.Item>
    </Form>
  </Modal>)
}
export default SavePipeline